const app = getApp()
//获得全局js变量
var util = require('../../utils/util.js');
Page({
    data: {
        rooturl: "https://www.zglianbang.com/api/miaozhimini/",
        isPartner: false,  // 是否是合伙人
        partnerInfo: {
            avatar: "/images/avatar.png",
            name: "张三",
            level: 3,
            isVerified: true,
            joinTime: "2023年5月",
            rankInfo: {
                rank: 5,
                progressPercent: 75  // 进度百分比，用于显示进度条
            },
            teamCount: 28,
            teamTrend: 3,  // 团队人数变化趋势，正数表示增加，负数表示减少
            monthPerformance: "¥15,680",
            performanceTrend: 12.5,  // 业绩变化趋势百分比
            totalCommission: "¥45,320",
            // 其他可能需要的数据
        },
        bannerList: [],
        // 添加公告数据
        noticeList: [],
        partnerNum:0
    },
    
    onLoad: function() {
        // 获取用户信息，判断是否是合伙人
		this.getBanner();
        this.getNews();
        var that=this;
        wx.request({
            url: that.data.rooturl + 'weixin/getUserInfo',
            data: {},
            header:{token:wx.getStorageSync('token')},
            success: function (res) {
                wx.hideLoading();
                var data = res.data.data;
                if(data.loginStatus == 2){
                    if(data.userPhone == '' || data.userPhone == null || data.userPhone == undefined){
                        
                    }else{
                        that.getParInfo();   
                    }
                }
            }
        })
    },
    getParInfo:function(){
        var that=this;
        util.httpRrquest(app.data.rooturl + 'weixin/getParInfo', 'GET')
        .then(function (response) {
            var data = response.data.data;
            that.setData({
                partnerNum: data.partnerNum
            })
            if(data.user.isPartner === 1){
                that.setData({
                    isPartner: true,
                    partnerInfo: data.user
                })
            }
        }, function (error) {
            console.log(error);
        });
    },
	getBanner:function(){
        var that=this;
        util.httpRrquest(app.data.rooturl + 'system/getBanner', 'GET')
        .then(function (response) {
            that.setData({
                bannerList: response.data.data
            })
        }, function (error) {
            console.log(error);
        });
    },
	getNews:function(){
        var that=this;
        util.httpRrquest(app.data.rooturl + 'system/getNews', 'GET')
        .then(function (response) {
            that.setData({
                noticeList: response.data.data
            })
        }, function (error) {
            console.log(error);
        });
	},
    // 申请成为合伙人
    applyForPartner: function() {
        var ifLogin = app.globalData.ifLogin;
        if (!ifLogin) {
            wx.navigateTo({
                url: '/pages/mine/auth/auth',
            });
            return;
        }else{
            wx.navigateTo({
                url: '/pages/partner/apply/apply',
            });
        }
        
    },
    
    // 添加导航到业绩页面的方法
    navigateToPerformance: function() {
        wx.navigateTo({
            url: '/pages/performance/performance'
        });
    },
    // 查看公告详情
    viewNoticeDetail: function(e) {
        const noticeId = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: `/pages/newDetail/newDetail?id=${noticeId}`,
        });
    },
    showCommissionDetail: function() {
        wx.navigateTo({
            url: '/pages/commissionDetail/commissionDetail',
        });	
    }
})